package plugincleaner.preferences;

import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

public class MyCleanButtonFieldEditor extends FieldEditor {

	private Button gCleanSelectedButton;
	private Button gCleanAllButton;

	private PluginTableController gController;

	public MyCleanButtonFieldEditor(String name, String labelText,
			Composite parent, PluginTableController controller) {
		super(name, labelText, parent);
		this.gController = controller;

	}

	@Override
	protected void adjustForNumColumns(int arg0) {
	}

	@Override
	protected void doFillIntoGrid(Composite parent, int arg1) {
		this.gCleanSelectedButton = new Button(parent, SWT.PUSH | SWT.BOTTOM
				| SWT.CENTER);
		this.gCleanSelectedButton.setText("Clean Selected");
		this.gCleanSelectedButton.setSize(25, 5);
		this.gCleanSelectedButton.setLayoutData(new GridData(SWT.FILL,
				SWT.FILL, false, false));
		this.gCleanSelectedButton.addListener(SWT.Selection, new Listener() {

			@Override
			public void handleEvent(Event event) {
				gController.removeSelectedPlugins();
			}

		});

		this.gCleanAllButton = new Button(parent, SWT.PUSH | SWT.BOTTOM
				| SWT.CENTER);
		this.gCleanAllButton.setText("Clean All");
		this.gCleanAllButton.setSize(25, 5);
		this.gCleanAllButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
				false, false));
		this.gCleanAllButton.addListener(SWT.Selection, new Listener() {

			@Override
			public void handleEvent(Event event) {
				gController.removeAllPlugins();
			}

		});
	}

	@Override
	protected void doLoad() {
	}

	@Override
	protected void doLoadDefault() {
	}

	@Override
	protected void doStore() {
	}

	@Override
	public int getNumberOfControls() {
		return 2;
	}

}
